//
//  UserHeaderView.m
//  ChangChat
//
//  Created by Cocoa on 2019/8/20.
//  Copyright © 2019 yibai. All rights reserved.
//

#import "UserHeaderView.h"

@interface UserHeaderView ()

@property (nonatomic, strong) UIView *msgContentView;
@property (nonatomic, strong) UILabel *msgContentLabel;
@property (nonatomic, strong) MASConstraint *bottomViewLayoutForBotom;

@end

@implementation UserHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
        [self setMsgContent:@""];
    }
    return self;
}
- (void)setupUI {
    
    self.iconImgView = [UIImageView new];
    self.nicknameLabel = [UILabel k_labelWithFontSize:15 textColor:UIColor.k_t2Color];
    self.mobileLabel = [UILabel k_labelWithFontSize:12 textColor:UIColor.k_t3Color];
    self.nicknameLabel.numberOfLines = 2;
    self.qqLabel = [ UILabel k_labelWithFontSize:12 textColor:UIColor.k_t3Color];
    self.editIconBtn = UIButton.k_init();
    self.editNicknameBtn = UIButton.k_init();
    UIImageView *rightArrowImgView = [[UIImageView alloc] initWithImage:UIImage.k_imgName(@"arrow_right")];
    self.rightArrowImgView = rightArrowImgView;
    
    self.msgContentView = [UIView new];
    self.msgContentView.layer.borderColor = UIColor.k_hexColor(0xe0e0e0).CGColor;
    self.msgContentView.layer.borderWidth = 0.5f;
    self.msgContentLabel = [UILabel k_labelWithFontSize:12 textColor:UIColor.k_t4Color];
    self.msgContentLabel.numberOfLines = 0;
    
    [self addSubview:self.iconImgView];
    [self addSubview:self.nicknameLabel];
    [self addSubview:self.mobileLabel];
    [self addSubview:self.qqLabel];
    [self addSubview:self.editNicknameBtn];
    [self addSubview:self.editIconBtn];
    [self addSubview:rightArrowImgView];
    [self addSubview:self.msgContentView];
    [self.msgContentView addSubview:self.msgContentLabel];
    
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(15);
        make.size.mas_equalTo(CGSizeMake(70, 70));
        make.bottom.mas_offset(-20).priorityLow();
    }];
    self.iconImgView.layer.cornerRadius = 35;
    self.iconImgView.layer.masksToBounds = YES;
    
    [self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImgView.mas_right).offset(5);
        make.top.equalTo(self.iconImgView).mas_offset(10);
        make.right.mas_offset(-15);
    }];
    
    [self.mobileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nicknameLabel);
        make.top.equalTo(self.nicknameLabel.mas_bottom).offset(10);
    }];
    
    [self.qqLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mobileLabel.mas_bottom).offset(3);
        make.left.right.equalTo(self.nicknameLabel);
    }];
    self.qqLabel.hidden = YES;
    
    [rightArrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-15);
        make.centerY.mas_offset(0);
    }];
    
    [self.editNicknameBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_offset(0);
        make.bottom.equalTo(self.iconImgView.mas_bottom).offset(20);
    }];
    [self.editIconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.iconImgView);
    }];
    
    [self.msgContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImgView);
        make.top.equalTo(self.iconImgView.mas_bottom).offset(20);
        make.right.equalTo(self.nicknameLabel);
        self.bottomViewLayoutForBotom = make.bottom.mas_offset(-15);
    }];
    [self.msgContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(15);
        make.right.mas_offset(-15);
        make.bottom.mas_offset(-15);
    }];
    
    self.iconImgView.image = UIImage.k_imgName(@"placeholder_user");
    self.nicknameLabel.text = @"昵称张三丰";
    self.mobileLabel.text = @"18866668888";
    
    self.msgContentLabel.text = @"某某某：文峰街道开始缴费卡开始的房间诶当副卡介绍的盛开的积分开始京东方";
}

- (void)setMsgContent:(NSString *)msgContent {
    _msgContent = msgContent;
    self.msgContentLabel.text = msgContent;
    
    if (msgContent.isHaveStr == YES) {
        self.msgContentView.hidden = NO;
        [self.bottomViewLayoutForBotom activate];
    } else {
        self.msgContentView.hidden = YES;
        [self.bottomViewLayoutForBotom deactivate];
    }
}

@end
